package xyz.bali16.application.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import xyz.bali16.application.entity.RoleMenu;
import xyz.bali16.application.mapper.RoleMenuMapper;
import xyz.bali16.application.service.RoleMenuService;

import java.util.Collection;


@Service
@AllArgsConstructor
public class RoleMenuServiceImpl extends ServiceImpl<RoleMenuMapper, RoleMenu> implements RoleMenuService {


    @Override
    public void removeByMenuId(Long menuId) {
        if (menuId == null) {
            return;
        }
        Wrapper<RoleMenu> wrapper = Wrappers.<RoleMenu>lambdaQuery()
                .eq(RoleMenu::getMenuId, menuId);
        remove(wrapper);
    }

    @Override
    public void removeByMenuId(Collection<Long> menuIds) {
        if (menuIds == null || menuIds.isEmpty()) {
            return;
        }
        Wrapper<RoleMenu> wrapper = Wrappers.<RoleMenu>lambdaQuery()
                .in(RoleMenu::getMenuId, menuIds);
        remove(wrapper);
    }

    @Override
    public void removeByRoleId(String roleId) {
        if (StrUtil.isEmpty(roleId)) {
            return;
        }
        Wrapper<RoleMenu> wrapper = Wrappers.<RoleMenu>lambdaQuery()
                .eq(RoleMenu::getRoleId, roleId);
        remove(wrapper);
    }
}
